function [ downSampledVals, systoleVel ] = processBeatGUI( ecgPeakVals, smoothedVelData, ...
    dicomImg, xAxisBottom, xAxisEndPoint, downThreshold, inputAxes, instructionText )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

% Figure out way to deal with user input

downSampleFlag = 0;

rWavePeaks = ecgPeakVals(1:2, 1); %Uses first two R-wave peaks to determine the axis scale
    
%% Find velocity during systole and get pixels per heart beat

ecgGatedVel = smoothedVelData;
    
% Selects for velocity values in systole. Sets all other velocity values to
% zero.
[systoleVel] = findEndSystole ( ecgGatedVel );

   
pixPerBeat = max(rWavePeaks) - min(rWavePeaks);
    
% Manual input now, but hope to OCR. Gets heart rate info for X axis scale
    
%% X axis Determination
    
[ secondsPerPixel ] = getBeatScaleGUI ( dicomImg, inputAxes, instructionText );
    
%% Y axis Determination

[ ocrResults ] = yAxisOCR ( dicomImg );
    
[ pixelsPerCmSec ] = getAxisScaleGUI ( dicomImg, ocrResults, xAxisBottom, xAxisEndPoint, inputAxes, instructionText );
[ pixelsPerCmSec ] = abs(pixelsPerCmSec); %corrects for improper axis scale segmentation (sometimes the axis marker is negative)
%% Determine Patient ID
    
%getPatientID
    
%% Axis Correction
normalizedSystoleVel = [];
    
normalizedSystoleVel(:, 3) = 1:length(systoleVel(:, 1));
    
    
% Normalizing Y axis
normalizedSystoleVel(:, 2) = systoleVel(:, 2) / pixelsPerCmSec;
    
% Normalizing X axis
    
normalizedSystoleVel(:, 3) = normalizedSystoleVel(:, 3) * secondsPerPixel;
    
%% Downsample data to threshold and refit
    
valsToDownsample = [];
    
valsToDownsample(:, 1) = normalizedSystoleVel(:, 3);
valsToDownsample(:, 2) = normalizedSystoleVel(:, 2);
    
[downSampledVals, downSampleFlag] = downsampleData(valsToDownsample, downThreshold, downSampleFlag);

if downSampleFlag == 0
    
    return
            
end

%Downsamples data more aggressively if insufficient post-systolic zero padding
warning('processBeat:UnableToDownsampleZeros', ...
['Insufficient post-systolic zero padding to perform down sampling to\n' ...
'%d points without further loss of data. Attempting to down sample \n' ...
'systolic values. Please review results following processing.'], downThreshold);
    
[downSampledVals] = downsampleAggressive(valsToDownsample, downThreshold);

    
end

